<style type="text/css" >
#add-actor-content{
  width: 99%;
  background: #FFF;
  display: block;
  border: 1px inset #888;
  padding: 5px;
  -moz-border-radius: 0px 0px 5px 5px;
  -webkit-border-radius: 0px 0px 5px 5px;
}
#add-actor-content label{
  display: inline-block;
  text-align: left;
  width: 100px;
  margin: 0px 5px 5px 5px;
  vertical-align: top;
}
.actor-input{
  width: 170px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border: 1px inset #888;
  padding: 1px 2px;
  vertical-align: top;
  margin-bottom: 2px;
}
.close-button{
  background: #f00;
  float:right;
  padding: 2px 4px 0px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  cursor: pointer;
  font-family: arial;
}
#add-actor-head{
  display:block;
  width: 99%;
  background: #1E4262;
  color: #FFF;
  padding: 5px;
  border: 1px solid #1E4262;
  -moz-border-radius: 5px 5px 0px 0px;
  -webkit-border-radius: 5px 5px 0px 0px;
}
.validation-errors{
  color: #F00;
  padding: 5px;
}
#valid-error{
  display: block;
  margin:0px 0px 5px 10px;
}
.required-field{
  color: #F00;
}
.actor-info-set{
  background: #EFEFEF;
  border: 1px inset #888;
  -moz-border-radius: 5px;
  -webkit-border-radius: 5px;
}
</style>

<script type="text/javascript">
$(document).ready(function(){
    $('#Employer').autocomplete({
        minLength: 1,
        source: "/matter/get-non-actors/",
        focus: function( event, ui ) {
            return false;
        },
        autoFocus: true,
        select: function( event, ui ) {
            $( "#Employer" ).val( ui.item.value );
            $( "#Employer-id" ).val( ui.item.id );
              return false;
        },
        change: function( event, ui ){
            valid=true;
            if ( !ui.item ) {
                valid=false;
            }
            if ( !valid ) {
                // remove invalid value, as it didn't match anything
                $(this).val( "" );
                $( "#Employer-id" ).val( "" );
                $(this).data( "autocomplete" ).term = "";
                return false;
            }
            return false;
        }
    });
    $('#parent_company').autocomplete({
        minLength: 1,
        source: "/matter/get-non-actors/",
        focus: function( event, ui ) {
            return false;
        },
        autoFocus: true,
        select: function( event, ui ) {
            $( "#parent_company" ).val( ui.item.value );
            $( "#parent_compnay-id" ).val( ui.item.id );
              return false;
        },
        change: function( event, ui ){
            valid=true;
            if ( !ui.item ) {
                valid=false;
            }
            if ( !valid ) {
                // remove invalid value, as it didn't match anything
                $(this).val( "" );
                $( "#parent_company-id" ).val( "" );
                $(this).data( "autocomplete" ).term = "";
                return false;
            }
            return false;
        }
    });
    $('#WorkSite').autocomplete({
        minLength: 1,
        source: "/matter/get-non-actors/",
        focus: function( event, ui ) {
            return false;
        },
        autoFocus: true,
        select: function( event, ui ) {
            $( "#WorkSite" ).val( ui.item.value );
            $( "#WorkSite-id" ).val( ui.item.id );
              return false;
        },
        change: function( event, ui ){
            valid=true;
            if ( !ui.item ) {
                valid=false;
            }
            if ( !valid ) {
                // remove invalid value, as it didn't match anything
                $(this).val( "" );
                $( "#WorkSite-id" ).val( "" );
                $(this).data( "autocomplete" ).term = "";
                return false;
            }
            return false;
        }
    });

    $('#nationality').autocomplete({
        minLength: 1,
        source: "/matter/get-country-codes/",
        focus: function( event, ui ) {
            return false;
        },
        autoFocus: true,
        select: function( event, ui ) {
            $( "#nationality" ).val( ui.item.value );
            $( "#nationality-code" ).val( ui.item.id );
                return false;
        },
        change: function( event, ui ){
            valid=true;
            if ( !ui.item ) {
                valid=false;
            }
            if ( !valid ) {
                // remove invalid value, as it didn't match anything
                $(this).val( "" );
                $( "#nationality-code" ).val( "" );
                $(this).data( "autocomplete" ).term = "";
                return false;
            }
            return false;
        }
    });


    $('#country').autocomplete({
        minLength: 1,
        source: "/matter/get-country-codes/",
        focus: function( event, ui ) {
            return false;
        },
        autoFocus: true,
        select: function( event, ui ) {
            $( "#country" ).val( ui.item.value );
            $( "#country-code" ).val( ui.item.id );
                return false;
        },
        change: function( event, ui ){
            valid=true;
            if ( !ui.item ) {
                valid=false;
            }
            if ( !valid ) {
                // remove invalid value, as it didn't match anything
                $(this).val( "" );
                $( "#country-code" ).val( "" );
                $(this).data( "autocomplete" ).term = "";
                return false;
            }
            return false;
        }
    });

    $('#country_mailing').autocomplete({
        minLength: 1,
        source: "/matter/get-country-codes/",
        focus: function( event, ui ) {
            return false;
        },
        autoFocus: true,
        select: function( event, ui ) {
            $( "#country_mailing" ).val( ui.item.value );
            $( "#country_mailing-code" ).val( ui.item.id );
                return false;
        },
        change: function( event, ui ){
            valid=true;
            if ( !ui.item ) {
                valid=false;
            }
            if ( !valid ) {
                // remove invalid value, as it didn't match anything
                $(this).val( "" );
                $( "#country_mailing-code" ).val( "" );
                $(this).data( "autocomplete" ).term = "";
                return false;
            }
            return false;
        }
    });

    $('#country_billing').autocomplete({
        minLength: 1,
        source: "/matter/get-country-codes/",
        focus: function( event, ui ) {
            return false;
        },
        autoFocus: true,
        select: function( event, ui ) {
            $( "#country_billing" ).val( ui.item.value );
            $( "#country_billing-code" ).val( ui.item.id );
                return false;
        },
        change: function( event, ui ){
            valid=true;
            if ( !ui.item ) {
                valid=false;
            }
            if ( !valid ) {
                // remove invalid value, as it didn't match anything
                $(this).val( "" );
                $( "#country_billing-code" ).val( "" );
                $(this).data( "autocomplete" ).term = "";
                return false;
            }
            return false;
        }
    });

    $('#default_role').autocomplete({
        minLength: 1,
        source: "/matter/get-actor-roles/",
        focus: function( event, ui ) {
            return false;
        },
        autoFocus: true,
        select: function( event, ui ) {
            $( "#default_role" ).val( ui.item.value );
            $( "#default_role-code" ).val( ui.item.id );
                return false;
        },
        change: function( event, ui ){
            valid=true;
            if ( !ui.item ) {
                valid=false;
            }
            if ( !valid ) {
                // remove invalid value, as it didn't match anything
                $(this).val( "" );
                $( "#default_role-code" ).val( "" );
                $(this).data( "autocomplete" ).term = "";
                return false;
            }
            return false;
        }
    });

    $('.close-button').click(function(){
        $('#actor-details-popup').css('display', 'none');
    });

    $('#add-actor-cancel').click(function(){
        $('#actor-details-popup').css('display', 'none');
    });

    $('#add-actor-submit').click(function(){
        $('#facade').css('height',$(document).height());
        $('#facade').css('display','block');
        $.ajax({
            url: '/matter/add-actor',
            type: 'POST',
            data: { name: $('#name').val(),
                    first_name: $('#first_name').val(),
                    display_name: $('#login').val(),
                    default_role: $('#default_role-code').val(),
                    function : $('#function').val(),
                    parent_ID:$('#parent_company-id').val(),
                    company_ID: $('#Employer-id').val(),
                    site_ID: $('#WorkSite-id').val(),
                    phy_person: $('input[name=phy_person]').val(),
                    small_entity: $('#small_entity').val(),
                    address: $('#address').val(),
                    nationality: $('#nationality-code').val(),
                    country: $('#country-code').val(),
                    address_mailing: $('#address_mailing').val(),
                    country_mailing: $('#country_mailing-code').val(),
                    address_billing: $('#address_billing').val(),
                    country_billing: $('#country_billing-code').val(),
                    email: $('#email').val(),
                    phone: $('#phone').val(),
                    phone2: $('#phone2').val(),
                    fax: $('#fax').val(),
                    pay_category: $('#pay_category').val(),
                    notes: $('#notes').val(),
                    VAT_number: $('#VAT_number').val(),
                  },
            success: function(response, status, xhr){
                if(response.length < 100){
                    var resObj = $.parseJSON(''+response);
                    $( "#actor" ).val( resObj.actor_name );
                    $( "#actor-id" ).val( resObj.actor_id );
                    $('#actor-details-popup').css('display', 'none');
                }else{
                    $('#actor-details-popup').html(response);
                }
                $('#facade').css('display','none');
            }
        });
    });
    $('#name').val($('#actor-name').val().toUpperCase());
    $("input:button").button();
});
</script>

<div id="add-actor-head">
Create Actor <span class="close-button">X</span>
</div>
<div id="add-actor-content">
<?php if(isset($this->formErrors)){ ?>
<div class="validation-errors" >
<?php foreach($this->formErrors as $key => $value){
   echo '<div class="valid-error">* '.$key.' - '.$value['isEmpty'].'</div>';
 } ?>
</div>
<?php } ?>
<?php if(isset($this->sqlErrors)){ ?>
<div class="validation-errors" >
<?php echo $this->sqlErrors;?>
</div>
<?php } ?>
<form id="add-actor-form" method="post" action="" >
<fieldset class="actor-info-set" >
<legend>Actor details</legend>
<label for="name" title="<?=$this->actorComments['name']?>" >Name <span class="required-field">*</span></label>
<?php echo $this->actorForm->getElement('name'); ?>
<label for="first_name" title="<?=$this->actorComments['first_name']?>" >Firstname</label>
<?php echo $this->actorForm->getElement('first_name'); ?>
<label for="display_name" title="<?=$this->actorComments['display_name']?>" >Display Name</label>
<?php echo $this->actorForm->getElement('display_name'); ?>
<label for="login" title="<?=$this->actorComments['login']?>" >Login</label>
<?php echo $this->actorForm->getElement('login'); ?>
<label for="default_role" title="<?=$this->actorComments['default_role']?>" >Default role</label>
<?php echo $this->actorForm->getElement('default_role'); ?>
<label for="function" title="<?=$this->actorComments['function']?>" >Function</label>
<?php echo $this->actorForm->getElement('function'); ?>
<label for="Employer" title="<?=$this->actorComments['company_ID']?>" >Employer</label>
<?php echo $this->actorForm->getElement('Employer'); ?>
<label for="parent_company" title="<?=$this->actorComments['parent_ID']?>" >Parent Company</label>
<?php echo $this->actorForm->getElement('parent_company'); ?>
<label for="WorkSite" title="<?=$this->actorComments['site_ID']?>" >Work Site</label>
<?php echo $this->actorForm->getElement('WorkSite');?>
<label for="phy_person" title="<?=$this->actorComments['phy_person']?>" >Physical Person</label>
<?php echo $this->actorForm->getElement('phy_person');?>
<label for="nationality" title="<?=$this->actorComments['nationality']?>" >Nationality</label>
<?php echo $this->actorForm->getElement('nationality');?>
<label for="small_entity" title="<?=$this->actorComments['small_entity']?>" >Small Entity</label>
<?php echo $this->actorForm->getElement('small_entity');?>
</fieldset>
<fieldset class="actor-info-set" >
<legend >Contact details</legend>
<label for="address" title="<?=$this->actorComments['address']?>" >Address</label>
<?php echo $this->actorForm->getElement('address');?>
<label for="country" title="<?=$this->actorComments['country']?>" >country</label>
<?php echo $this->actorForm->getElement('country');?>
<label for="address_mailing" title="<?=$this->actorComments['address_mailing']?>" >Address mailing</label>
<?php echo $this->actorForm->getElement('address_mailing');?>
<label for="country_mailing" title="<?=$this->actorComments['country_mailing']?>" >Country mailng</label>
<?php echo $this->actorForm->getElement('country_mailing');?>
<label for="address_billing" title="<?=$this->actorComments['address_billing']?>" >Address Billing</label>
<?php echo $this->actorForm->getElement('address_billing');?>
<label for="country_billing" title="<?=$this->actorComments['country_billing']?>" >Country Billing</label>
<?php echo $this->actorForm->getElement('country_billing');?>
<label for="email" title="<?=$this->actorComments['email']?>" >Email</label>
<?php echo $this->actorForm->getElement('email');?>
<label for="phone" title="<?=$this->actorComments['phone']?>" >Phone</label>
<?php echo $this->actorForm->getElement('phone');?>
<label for="phone2" title="<?=$this->actorComments['phone2']?>" >Phone 2</label>
<?php echo $this->actorForm->getElement('phone2');?>
<label for="fax" title="<?=$this->actorComments['fax']?>" >Fax</label>
<?php echo $this->actorForm->getElement('fax');?>
</fieldset>
<fieldset class="actor-info-set" >
<legend>Other details</legend>
<label for="pay_category" title="<?=$this->actorComments['pay_category']?>" >Pay Category</label>
<?php echo $this->actorForm->getElement('pay_category');?>
<label for="VAT_number" title="<?=$this->actorComments['VAT_number']?>" >VAT No.</label>
<?php echo $this->actorForm->getElement('VAT_number');?>
<label for="notes" title="<?=$this->actorComments['notes']?>" >Notes</label>
<?php echo $this->actorForm->getElement('notes');?>
</fieldset>

<input type="hidden" value="" id="Employer-id" name="Employer-id"/>
<input type="hidden" value="" id="parent_company-id" name="parent_company-id"/>
<input type="hidden" value="" id="WorkSite-id" name="WorkSite-id"/>
<input type="hidden" value="" id="country-code" name="country-code"/>
<input type="hidden" value="" id="nationality-code" name="country-code"/>
<input type="hidden" value="" id="country_mailing-code" name="country_mailing-code"/>
<input type="hidden" value="" id="country_billing-code" name="country_billing-code"/>
<input type="hidden" value="<?=$this->default_role_code?>" id="default_role-code" name="default_role-code"/>

<div style="text-align: center; margin-top:5px;">
<input type="button" value="Create" name="add-actor-submit" id="add-actor-submit" />
<input type="button" value="Cancel" name="add-actor-cancel" id="add-actor-cancel" />
</div>
</form>
</div>
